<template>
  <div class="distribution-config">
    <h2>分销配置</h2>
    <el-table :data="configData" border style="width: 100%">
      <el-table-column prop="settlementDay" label="每月结算日" width="180">
        <template #default="scope">
          <span>{{ scope.row.settlementDay }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="minWithdrawalAmount" label="最低提现金额" width="180">
        <template #default="scope">
          <span>{{ scope.row.minWithdrawalAmount }}元</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="180">
        <template #default="scope">
          <el-button size="small" @click="handleEdit(scope.$index, scope.row)">修改</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-dialog v-model="dialogVisible" title="修改分销配置">
      <el-form :model="editForm" label-width="120px">
        <el-form-item label="每月结算日">
          <el-input-number v-model="editForm.settlementDay" :min="1" :max="31"></el-input-number>
        </el-form-item>
        <el-form-item label="最低提现金额">
          <el-input-number v-model="editForm.minWithdrawalAmount" :min="0" :precision="2"></el-input-number>
        </el-form-item>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="dialogVisible = false">取消</el-button>
          <el-button type="primary" @click="saveEdit">保存</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "distributionConfig",
  data() {
    return {
      configData: [
        { settlementDay: 15, minWithdrawalAmount: 100 },
        { settlementDay: 20, minWithdrawalAmount: 200 }
      ],
      dialogVisible: false,
      editForm: {
        settlementDay: 0,
        minWithdrawalAmount: 0
      },
      currentIndex: -1
    };
  },
  methods: {
    handleEdit(index, row) {
      this.currentIndex = index;
      this.editForm.settlementDay = row.settlementDay;
      this.editForm.minWithdrawalAmount = row.minWithdrawalAmount;
      this.dialogVisible = true;
    },
    saveEdit() {
      this.configData[this.currentIndex].settlementDay = this.editForm.settlementDay;
      this.configData[this.currentIndex].minWithdrawalAmount = this.editForm.minWithdrawalAmount;
      this.dialogVisible = false;
    }
  }
};
</script>

<style scoped lang="scss">
.distribution-config {
  padding: 20px;
}
</style>
